package com.gxgeek.javabasic.collection.list.arraylist;

import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;

/**
 * Created by GX on 2017/8/18.
 */
public class AnalyzelArrayList {

    public static void main(String[] args) {
        noArgsConstructor();
        initCapacity();
//        sysCopy();
    }

    private static void noArgsConstructor() {
        long start = System.currentTimeMillis();
        ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < 1000; i++) {
            list.add("sh" + i);
        }
        long end = System.currentTimeMillis();
        System.out.println("没有初始化容量所需時間 ：" + (end - start));
    }

    private static void initCapacity() {
        long start = System.currentTimeMillis();
        ArrayList<String> list = new ArrayList<String>(1000);
        for (int i = 0; i < 1000; i++) {
            list.add("sh" + i);
        }
        long end = System.currentTimeMillis();
        System.out.println("初始化了容量所需時間   ：" + (end - start));
    }

    static void sysCopy() {
        ArrayList<String> list = new ArrayList<String>();
        int[] ints = new int[]{1, 2, 3, 6, 5, 7, 9};
        ints = Arrays.copyOf(ints, 50);
        Arrays.stream(ints).forEach(System.out::println);
        ints = null;
    }
}
